Working with Vector Data in sf
sf is a new package and apepars to be the leading contender to replace rgdal and sp. sf reads and writes shapefiles and also has a large number of vector transforms available (see resources at the bottom of the page).
Reading and Displaying Data
The code below will read a shapefile into a data table.
# Load library library('sf') library("tibble") # required for read (at least). This installs about 10 other libraries FilePath="D:/GISData/2_Working/WGS84_UTM_Zone_10_North/County_Humboldt/Cities/cities2sp.shp" # Loads data table TheCities <- read_sf(FilePath) plot(TheCities)
Because we now have a data frame, all of the other functions such as nrow() and ncol() work with the data.
Coordinate Reference Systems
You can use Proj strings to create Coordinate Reference Systems (crs) (a.k.a. Spatial Reference Systems). The example below creates an unproject (geographic) crs and then create a vector dataset that uses that crs.
crdref <- "+proj=longlat +datum=WGS84" pts <- vect(lonlat, crs=crdref)
Additional Resources
Simple Features for R - website for SF with great quick reference.
Spatial Data Science - Vector Data - great detailed explaination of tarra.